var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        loanId:'',
        programId:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.loanId = Pub.getSession('loanId');
        this.params.loanSn = Pub.getSession('loanSn');
        if (Pub.getSession('state')==0) {
            $('#billtitle').text('账单详情-还款中');
            $('#currentBill').text('当前订单状态：还款中');
        }else if(Pub.getSession('state')==1){
            $('#billtitle').text('账单详情-已结清');
            $('#currentBill').text('当前订单状态：已结清');
        }else{
            $('#billtitle').text('账单详情-已逾期');
            $('#currentBill').text('当前订单状态：已逾期');
        };
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            loanId:_this.params.loanId
        };
        Api.billingdetails(paramsObj, function(data){
            console.log(data);
            _this.getDataList(data)
        });
    },
    getDataList: function(data) {
        var _this = this;
        if (JSON.stringify(data) != "{}") {
            var html = '';
            for(i in data){

                _this.params.programId=data[i].programId;

              html +='<tr>';

                html +='<td class="text-c">'+data[i].batch+' </td>'+
                    '<td class="text-c">'+data[i].repayDate+'</td>'+
                    '<td class="text-c">￥'+data[i].money+'</td>';
            if (data[i].isRepay==0) {
                if (data[i].overdueDays>0) {
                    html +='<td class="text-c">已逾期</td>';
                }else{
                    html +='<td class="text-c">还款中</td>';
                };

            }else{
                html +='<td class="text-c">已还清</td>';
            };
                html +='<td class="text-c">￥'+data[i].actualRepaymentAmount+'</td>'+
                        '<td class="text-c">'+data[i].overdueDays+'</td>'+
                '</tr>';
            }
            $('#List').html(html);
        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="7" >暂无数据</td>' +
                '</tr>';
            $('#List').html(html);
        }
    },
    getOperatData:function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            loanId:_this.params.loanId
        };
        Api.operationalinformationlist(paramsObj, function(data){
            console.log(data);
            _this.getOperatList(data)
        });
    },
    getOperatList: function(data) {
        var _this = this;

        if (JSON.stringify(data) != "{}") {
            var html = '';
            for(i in data){
                html +='<tr>';
                html +='<td class="text-c">'+data[i].gmtCreate+' </td>';

            if (data[i].status==0) {
                html +='<td class="text-c">-</td>'+
                        '<td class="text-c">-</td>';
            }else if (data[i].status==1) {
                html +='<td class="text-c">全还 </td>'+
                        '<td class="text-c">全还 </td>';
            }else if (data[i].status==2) {
                html +='<td class="text-c">部分还 </td>'+
                        '<td class="text-c">部分还 </td>';
            };
                html +='<td class="text-c">'+data[i].remark+'</td>'+
                '</tr>';
            }
            $('#opList').html(html);
        } else {
            html = '<tr>' +
                '<td class="text-c c-666" colspan="4" >暂无数据</td>' +
                '</tr>';
            $('#opList').html(html);
        }
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('#remarkBtn').click(function(event) {
            $('#modal_remark').modal('show');
            $('#remarkVal').val('');
        });
        $('#remarkYes').click(function(event) {
            var remark=$('#remarkVal').val();
            var paramsObj = {
                passport: _this.params.passport,
                orderSn:_this.params.loanSn,
                stagesId:_this.params.programId,
                remark:remark
            };
            console.log(paramsObj);
            Api.reimbursementlogadd(paramsObj, function(data){
                console.log(data);
                layui.use('layer', function(){
                    layer.msg('备注成功', {icon: 6});
                });
                _this.getOperatData();
                $('#modal_remark').modal('hide');
            });
        });
    },
    initEvent: function(){
        var _this = this;
         _this.getData();
        _this.otherEvent();
        _this.getOperatData();


    }
};
var page = new Page();